import {
  evaluateInit,
  submitEvaluate
} from '../../../utils/networkRequest.js'
// pages/evaluate/evaluate.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oneNum: 5,
    dataInfo: null,

  },
  remark: "", //备注
  in_onestart: function(e) {
    console.log(e.currentTarget.id)

    this.setData({
      onemstart: Number(e.currentTarget.id)
    })
  },
  in_towstart: function(e) {
    console.log(e.currentTarget.id)

    this.setData({
      towmstart: Number(e.currentTarget.id)
    })
  },
  in_threestart: function(e) {
    console.log(e.currentTarget.id)

    this.setData({
      threemstart: Number(e.currentTarget.id)
    })
  },
  in_fourstart: function(e) {
    console.log(e.currentTarget.id)

    this.setData({
      fourmstart: Number(e.currentTarget.id)
    })
  },
  //获取备注
  getRemark: function(e) {
    this.setData({
      remark: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let self = this;
    evaluateInit(options.mid, (r) => {
      console.log(r);
      if (r.code == 0) {
        self.setData({
          mid: options.mid,
          rid: options.rid,
          dataInfo: r.data
        })
      }
    })
  },
  //提交评价
  onSubmit: function() {
    let {
      mid,
      rid,
      remark,
      dataInfo,
      onemstart,
      towmstart,
      threemstart,
      fourmstart
    } = this.data;

    let obj = [{
        mtype: dataInfo.rating_main.id,
        score: onemstart
      },
      {
        mtype: dataInfo.rating_type[0].id,
        score: towmstart
      }, {
        mtype: dataInfo.rating_type[1].id,
        score: threemstart
      }, {
        mtype: dataInfo.rating_type[2].id,
        score: fourmstart
      }
    ]
    submitEvaluate(mid, remark, rid, obj, (r) => {
      if (r.code == 0) {
       wx.showToast({
         icon:'none',
         title: '评论成功',
       })
      }
     
      wx.navigateBack();
    })
  }
})